package com.block.common.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @date 2021/3/4 12:06 下午
 */
public class MapUtil {


    /**
     * 将ParameterMap转为Map<String,String>
     * @param params
     * @return
     */
    public static Map<String,String> mapArrayToMapStr(Map<String,String[]> params) throws UnsupportedEncodingException {
        if(CollUtil.isEmpty(params)){
            return  null;
        }
        Map<String,String> resultMapping = new HashMap<>();
        for(String key:params.keySet()){
            String [] result=params.get(key);
            if(ObjectUtil.isNotEmpty(result)) {
                resultMapping.put(key, URLDecoder.decode(result[0],"utf-8") );
            }
        }
        return resultMapping;
    }
}
